package com.logic.view

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.Switch
import com.logic.idevice.impl.common.CommonSetting
import com.logic.idevice.impl.kv7.Kv7Setting
import com.uhf.uhf.R

/**
 * create by lwj at 2022/7/25
 * 切换 epc user区域的操作
 */
class Kv7EpcUserSwitchView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : FrameLayout(context, attrs) {

    private val root = inflate(context, R.layout.layout_device_kv7_ui, this)

    private val epc = root.findViewById<Switch>(R.id.hint_sing_switch_epc)

    private val user = root.findViewById<Switch>(R.id.hint_sing_switch_user)

    var onEnsureState:(()->Unit)?=null
    var onClickChange: ((isEpc: Boolean) -> Unit)? = null

    //默认为 epc 每次初始化必须 给它赋值
    var isEpc: Boolean = true
        set(value){
            field = value
            ensureStates()
        }

    init {

        epc.setOnClickListener {
            onClickChange?.invoke(true)
        }
        user.setOnClickListener {
            onClickChange?.invoke(false)
        }

    }

    private fun ensureStates() {
        epc.isChecked = isEpc
        user.isChecked = !isEpc

        onEnsureState?.invoke()
    }

}